package xyz.gzdxc.common.mysql.repository;

import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import xyz.gzdxc.common.mysql.entity.MenuEntity;

import java.util.List;

@Repository
public interface MenuRepository extends CrudRepository<MenuEntity, Long> {
    /**
     * get the menu list by user id
     */
    @Query("select m.id as id, m.menu_code as menu_code, m.par_menu_code as par_menu_code, m.menu_name as menu_name, m.name as name, m.path as path, m.priv_code as priv_code, m.sequence as sequence, m.icon as icon from xh_cm_group_user gu join xh_cm_group_priv gp on (gu.del_status='0' and gp.del_status='0' and gu.group_id=gp.group_id) join xh_cm_priv p on (p.del_status='0' and p.id=gp.priv_id) join xh_cm_menu m on (p.priv_code=m.priv_code and m.del_status='0') where gu.user_id = :userId order by m.sequence desc")
    List<MenuEntity> getMenuListByUserId(@Param("userId") Long userId);
}
